package com.cfl.ticketmodule.service.impl;

import java.util.ArrayList;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cfl.model.City;
import com.cfl.ticketmodule.dao.CityMapper;
import com.cfl.ticketmodule.service.CityService;

@Service
public class CityServiceImpl implements CityService{

	@Autowired
	private CityMapper cityMapper;
	
	public void addCity(String name, String pinyin) throws Exception{
		try {
			City city = new City();
			city.setCid(UUID.randomUUID().toString());
			city.setName(name);
			city.setPinyin(pinyin);
			cityMapper.insert(city);
		} catch (Exception e) {
			throw e;
		}
	}
	
	public City findByCid(String cid) throws Exception {
		try {
			return cityMapper.selectByCid(cid);
		} catch (Exception e) {
			throw e;
		}
	}
	
	public City findByName(String name) throws Exception {
		try {
			return cityMapper.selectByName(name);
		} catch (Exception e) {
			throw e;
		}
	}
	
	public ArrayList<City> findCityByAll() throws Exception {
		try {
			return cityMapper.selectByAll();
		} catch (Exception e) {
			throw e;
		}
	}
}
